using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace WebDauGia.Domain.Models.Mapping
{
    public class DonDatHangMap : EntityTypeConfiguration<DonDatHang>
    {
        public DonDatHangMap()
        {
            // Primary Key
            this.HasKey(t => t.id);

            // Properties
            this.Property(t => t.sodt)
                .HasMaxLength(20);

            this.Property(t => t.email)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("DonDatHang");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.idkhachhang).HasColumnName("idkhachhang");
            this.Property(t => t.idtrangthai).HasColumnName("idtrangthai");
            this.Property(t => t.ngaydat).HasColumnName("ngaydat");
            this.Property(t => t.idpttt).HasColumnName("idpttt");
            this.Property(t => t.idptgh).HasColumnName("idptgh");
            this.Property(t => t.ghichu).HasColumnName("ghichu");
            this.Property(t => t.diachi).HasColumnName("diachi");
            this.Property(t => t.sodt).HasColumnName("sodt");
            this.Property(t => t.email).HasColumnName("email");
            this.Property(t => t.tenkh).HasColumnName("tenkh");

            // Relationships
            this.HasRequired(t => t.KhachHang)
                .WithMany(t => t.DonDatHangs)
                .HasForeignKey(d => d.idkhachhang);
            this.HasRequired(t => t.PhuongThucGiaoHang)
                .WithMany(t => t.DonDatHangs)
                .HasForeignKey(d => d.idptgh);
            this.HasRequired(t => t.PhuongThucThanhToan)
                .WithMany(t => t.DonDatHangs)
                .HasForeignKey(d => d.idpttt);
            this.HasRequired(t => t.TrangThaiDonHang)
                .WithMany(t => t.DonDatHangs)
                .HasForeignKey(d => d.idtrangthai);

        }
    }
}
